﻿using RightControl.Common;
using RightControl.IRepository;
using RightControl.IService;
using RightControl.Model;
using System.Collections.Generic;
using RightControl.Service;
using RightControl.Repository.Product;

namespace RightControl.Service {
    public class SubProductImageService : BaseService<SubProductImage>, ISubProductImageService {
        public ISubProductImgRepository repository { get; set; }

        public int SaveSubProductImages(IEnumerable<SubProductImage> entitys) {
            return repository.SaveSubProductImages(entitys);
        }


        public dynamic GetListByFilter(SubProductImage filter, PageInfo pageInfo) {
            string _where = " where 1=1";
            _where += string.Format(" and ProductId = {0}", filter.ProductId);
            return GetListByFilter(filter, pageInfo, _where);
        }

        public List<SubProductImage> GetSubProductImageList(SubProductImage filter, PageInfo pageInfo) {
            List<SubProductImage> subProdList = new List<SubProductImage>();

            dynamic subProdRet = GetListByFilter(filter, pageInfo);

            if (subProdRet != null && subProdRet.count > 0) {
                subProdList = subProdRet.data as List<SubProductImage>;
            }
            return subProdList;
        }

        //public List<SubProduct> GetSubProductList(SubProduct filter, PageInfo pageInfo) {
        //    List<SubProduct> subProdList = new List<SubProduct>();
       
        //    dynamic subProdRet = GetListByFilter(filter, pageInfo);
        //    if (subProdRet != null && subProdRet.count > 0) {
        //        subProdList = subProdRet.data as List<SubProduct>;
        //    }
        //    return subProdList;
        //}

        public bool DeleteByProdcutId(int productId, int userId =0) {
            string _where = " where 1=1";
            _where += string.Format(" and ProductId = {0}", productId);
            if (userId > 0) {
                _where += string.Format(" and CreateBy = {0}", userId);
            }
            return DeleteByWhere(_where);
        }


        public int UpdateSubProducts(IEnumerable<SubProductImage> entitys, string updatefields = null) {
            return repository.UpdateSubProductsImages(entitys, updatefields);
        }

        //public dynamic GetListByFilter(SubProductImage filter, PageInfo pageInfo) {
        //    return repository.GetByWhere(entitys);
        //}
    }
}